package com.ys.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * <p>@description:</p>
 *
 * @projectName: Spring-Mini
 * @packageName: com.com.ys.io
 * @className:
 * @author: shuangyang
 * @date: 1/14/17 11:12 PM
 */
public class UrlResource implements Resource {


    /**
     *资源路径
     */
    private final URL url;

    public UrlResource(URL url) {
        this.url = url;
    }

    /**
     * 通过资源的url获取资源
     *
     * @return
     * @throws IOException
     */
    @Override
    public InputStream getInputStream() throws IOException {
        /*打开一个资源路径的链接*/
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        return urlConnection.getInputStream();
    }
}
